package com.mjh.zhujianju.controller.party;

import com.livew.framework.base.controller.BaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.exception.XTBusinessException;
import com.livew.framework.page.PagedResult;
import com.livew.framework.pojo.AjaxResult;
import com.mjh.zhujianju.model.party.BuildingEventEO;
import com.mjh.zhujianju.model.party.BuildingEventUsersEO;
import com.mjh.zhujianju.service.party.BuildingEventSercice;
import com.mjh.zhujianju.vo.party.BuildingEventUsersVO;
import com.mjh.zhujianju.vo.party.BuildingEventVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: Alex
 * @version: V1.0
 * @project: zhujianju
 * @package: com.mjh.zhujianju.controller.party
 * @description: description
 * @date: 2018/8/16
 * @time: 下午4:35
 */
@Controller()
@RequestMapping("party/event")
public class EventController extends BaseController<BuildingEventEO> {

    @Autowired
    private BuildingEventSercice buildingEventSercice;

    @Override
    protected BaseService<BuildingEventEO> getService() {
        return buildingEventSercice;
    }

    @RequestMapping(value = "getPage", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getPage(BuildingEventVO buildingEventVO) {
        PagedResult<BuildingEventVO> list = buildingEventSercice.findBuildingEventPagination(buildingEventVO);
        return AjaxResult.getResult(list);
    }

    @RequestMapping(value="saveEventInfo",method=RequestMethod.POST)
    @ResponseBody
    public AjaxResult saveEventInfo(BuildingEventVO buildingEventVO) {
        if(buildingEventVO==null) {
            return AjaxResult.getResult(Boolean.FALSE, "参数错误" );
        }
        try {
            buildingEventSercice.saveInfo(buildingEventVO);

        }catch (XTBusinessException e) {
            e.printStackTrace();
            return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
        }
        return AjaxResult.getResult(Boolean.TRUE, "保存成功");
    }

    @RequestMapping(value = "editEvent/{id}", method = RequestMethod.GET)
    public String editEvent(@PathVariable("id") Long id, Model model) {
        BuildingEventVO buildingEventVO = buildingEventSercice.queryBuildingEventInfo(id);
        model.addAttribute("buildingEvent", buildingEventVO);
        return "party/event/create";
    }

    @Override
    public AjaxResult findById(@PathVariable("id") Long id) {
        if (id == null) {
            return AjaxResult.getResult(Boolean.FALSE, "参数错误");
        }
        BuildingEventVO t = null;
        try {
            t =this.buildingEventSercice.getInfo(id);
        } catch (XTBusinessException e) {
            e.printStackTrace();
            return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
        }
        return AjaxResult.getResult(t);
    }

    @RequestMapping(value = "detailEvent/{id}", method = RequestMethod.GET)
    public String detailMeeting(@PathVariable("id") Long id, Model model) {
        BuildingEventVO buildingEventVO = buildingEventSercice.queryBuildingEventInfo(id);
        model.addAttribute("buildingEvent", buildingEventVO);
        return "party/event/detail1";
    }

    @RequestMapping(value = "detailSign/{id}", method = RequestMethod.GET)
    public String detailSign(@PathVariable("id") Long id, Model model) {
        return "party/meeting/detail2";
    }

    @RequestMapping(value = "showSign", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult showSign(BuildingEventUsersVO buildingEventUsersVO) {
        BuildingEventUsersEO buildingEventUsersEO = new BuildingEventUsersEO();
        BeanUtils.copyProperties(buildingEventUsersVO,buildingEventUsersEO);
        PagedResult<BuildingEventUsersVO> list = buildingEventSercice.findBuildingEventUsersPagination(buildingEventUsersEO);
        return AjaxResult.getResult(list);
    }
}
